package com.example.administrator.tenyuanpackage.speacial;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.tenyuanpackage.R;
import com.example.administrator.tenyuanpackage.speacial.adapter.TeMaiViewPagetAdapter;
import com.example.administrator.tenyuanpackage.speacial.fragment.TeMaiFragment;

import java.util.ArrayList;

import butterknife.ButterKnife;


public class SpeacialOfferFragment extends Fragment {

    private Context mContext=getContext();
    public SpeacialOfferFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_speacial_offer, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        TabLayout tbSof = (TabLayout) view.findViewById(R.id.tb_sof);
        ViewPager vpSof = (ViewPager) view.findViewById(R.id.vp_sof);
        String [] titles={"最新上线","昨日上新","最后疯抢","精致女装","鞋包配件"};
        ArrayList<Fragment> fragments=new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            fragments.add(TeMaiFragment.getInsatance(i));
        }
        tbSof.setTabTextColors(Color.BLACK,Color.RED);
        tbSof.setTabMode(TabLayout.MODE_SCROLLABLE);
        tbSof.setSelectedTabIndicatorColor(Color.RED);
        //界面之间来回切换都不会重新加载

        vpSof.setOffscreenPageLimit(fragments.size());
        vpSof.setAdapter(new TeMaiViewPagetAdapter(getFragmentManager(),mContext,fragments,titles));

        tbSof.setupWithViewPager(vpSof);
    }
}
